package com.sky.controller.admin;

import com.sky.dto.ArticlePageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.HomeService;
import com.sky.vo.ArticleInfoVO;
import com.sky.vo.HomeOtherVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 贾晓晨
 * @version 1.0
 */
@RestController
@RequestMapping("/home")
@Slf4j
@Api(tags = "首页内容接口")
public class HomeController {
    // 获取tag列表
    @Autowired
    private HomeService homeService;

    @GetMapping("/tag")
    @ApiOperation("获取首页的tag标签列表")
    public Result<List<String>> getTagList() {
        List<String> tagList = homeService.getTagList();
        if (tagList == null || tagList.isEmpty()) {
            return Result.error("标签列表为空");
        }
        return Result.success(tagList);
    }

    @GetMapping("/articleInfo")
    @ApiOperation("获取首页的文章列表")
    public Result<PageResult> getArticleList(ArticlePageQueryDTO articlePageQueryDTO) {
        PageResult articleList = homeService.getArticleList(articlePageQueryDTO);
        return Result.success(articleList);
    }

    @GetMapping("/other")
    @ApiOperation("页面除tag和首页其他")
    public Result<HomeOtherVO> getOtherList() {
        // 获取所有的其他消息
        HomeOtherVO homeOtherVO = homeService.getOther();
        return Result.success(homeOtherVO);
    }
}
